

package com.sihai.gateway;

import com.sihai.gateway.predicate.factory.*;
import com.sihai.gateway.route.RouteDefinitionLocator;
import com.sihai.gateway.support.ClientIpResolver;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @author sihai
 */
@Configuration
@ConditionalOnWebApplication(type = Type.SERVLET)
public class GatewayRoutePredicateAutoConfiguration {

    @Bean
    public CookieRoutePredicateFactory cookieRoutePredicateFactory() {
        return new CookieRoutePredicateFactory();
    }

    @Bean
    public HeaderRoutePredicateFactory headerRoutePredicateFactory() {
        return new HeaderRoutePredicateFactory();
    }

    @Bean
    public MethodRoutePredicateFactory methodRoutePredicateFactory() {
        return new MethodRoutePredicateFactory();
    }

    @Bean
    public PathRoutePredicateFactory pathRoutePredicateFactory() {
        return new PathRoutePredicateFactory();
    }

    @Bean
    public ParameterRoutePredicateFactory parameterRoutePredicateFactory() {
        return new ParameterRoutePredicateFactory();
    }

    @Bean
    public BodyRoutePredicateFactory bodyRoutePredicateFactory() {
        return new BodyRoutePredicateFactory();
    }

    @Bean
    public ClientIpRoutePredicateFactory clientIpRoutePredicateFactory(
            ClientIpResolver clientIpResolver) {
        return new ClientIpRoutePredicateFactory(clientIpResolver);
    }

    @Bean
    public AfterRoutePredicateFactory afterRoutePredicateFactory() {
        return new AfterRoutePredicateFactory();
    }

    @Bean
    public BeforeRoutePredicateFactory beforeRoutePredicateFactory() {
        return new BeforeRoutePredicateFactory();
    }

    @Bean
    public BetweenRoutePredicateFactory betweenRoutePredicateFactory() {
        return new BetweenRoutePredicateFactory();
    }


    @Bean
    public WeightRoutePredicateFactory weightRoutePredicateFactory(
            @Lazy RouteDefinitionLocator routeDefinitionLocator) {
        return new WeightRoutePredicateFactory(routeDefinitionLocator);
    }
}
